<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    ErrorController
 * @category   Controller
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */

/**
 * Processes any error thrown inthe application
 *
 * @package    ErrorController
 * @category   Controller
 */
class Error_ErrorController extends Zend_Controller_Action
{
    /**
     * Error action to process any errors coming from the application
     *
     */
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        
        $config = Zend_Registry::get('config');
        
        $this->getResponse()->clearBody();
                
        $title = '';
        $message = '';
        
        switch ($errors->type) {
	        case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
	        case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
	            // 404 error -- controller or action not found
	            $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
	            $message = 'error-error-error:404:message';
	            $title = 'error-error-error:404:header';
	            break;
	        default:
	            $exception = $errors->exception;
	            if ($exception instanceof Ot_Exception) {
	            	$title = $exception->getTitle();
	            } else {
	            	$title = 'error-error-error:generic';
	            }
	            
	            $this->view->showTrackback = $config->user->showTrackbackOnErrors->val;
	            $this->view->trackback     = $exception->getTrace();
	            $message = $exception->getMessage();
	            break;
        }
        
        $this->_helper->pageTitle($title);
        
        $this->view->title = $this->view->translate('error-error-error:title') . ' ' . $this->view->title;
        $this->view->message = $message;
    }
}